/**
 * Custom renderer for the ItemClass table, adds Icons to the entries
 * 
 * @author remo.lemma@lu.unisi.ch
 */

package ch.unisi.inf.projects.java.uom.gui.table.itemclass;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import ch.unisi.inf.projects.java.uom.gui.UOMImages;

public class UOMItemClassTableCellRenderer extends DefaultTableCellRenderer
{
	/** We are not going to serialize this class atm */
    private static final long serialVersionUID = -1L;
    
	private final ImageIcon icon = new ImageIcon(getClass().getResource(UOMImages.ITEMCLASS.getFileName()));
	private final ImageIcon allIcon = new ImageIcon(getClass().getResource(UOMImages.ALLITEMCLASSES.getFileName()));
	
	public UOMItemClassTableCellRenderer ()
	{
		super();
	}
    
	public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) 
	{
    	super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    	setText(value.toString());
    	setToolTipText("<html><b>Category:</b> " + value.toString());
    	ImageIcon i = null;
    	if (value.toString().equals("ALL CATEGORIES"))
    		i = allIcon;
    	else
    		i = icon;
    	setIcon(i);
    	return this;
    	
    }
}